<!-- 
All rights Reserved, Designed By www.youyacao.com 
@Description:卡密交易记录
@author:成都市一颗优雅草科技有限公司     
@version 松鼠聚合直播系统v2.0
注意：本前端源码遵循 MulanPSL-2.0开源协议（木兰宽松许可证）本内容仅限于个人参考，禁止用于其他的商业用途
需要商业用途或者定制开发等可访问songshu.youyacao.com   联系QQ:422108995 23625059584

 -->

<template>
    <div>
        <van-nav-bar
                title="卡密交易记录"
                left-text="返回"
                left-arrow
                fixed
                @click-left="onClickLeft"
        />
        <div style="padding-top: 46px;">
            <div class="item-box" v-for="(item,index) in list.data">
                <van-row class="item-title">
                    <van-col span="16" class="order">{{item.order_no}}</van-col>
                    <van-col span="8" class="money">
                        <span class="grey" v-if="item.payed_time=='未支付'">{{item.need_money ? '+'+item.need_money : item.need_money}}</span>
                        <span class="blue" v-else-if="item.type== '购买卡密'">-{{item.need_money}}</span>
                        <span class="red" v-else-if="parseFloat(item.need_money)>0">+{{item.need_money}}</span>
                        <span class="blue" v-else-if="parseFloat(item.need_money)<=0">{{item.need_money}}</span>
                    </van-col>
                </van-row>
                <div class="item-row">交易类型：[{{item.type}}] <van-button type="primary" size="small" @click="showCards(item.id)" style="margin-left: 30px;">查看卡密</van-button></div>
                <div class="item-row text">{{item.info}}</div>
                <div class="item-row" v-if="item.buyuser">购买用户：{{item.buyuser}}</div>
                <div class="item-row">创建时间：{{item.create_time}}</div>
                <div class="item-row">完成时间：<span :style="item.payed_time=='未支付' ?  'color:red' : ''">{{item.payed_time}}</span><van-button v-if="item.payed_time=='未支付' && userinfo.id == item.user_id" style="margin-left: 30px;" size="small" type="primary" @click="doPayMoney(item.id)">完成支付</van-button></div>
            </div>
            <van-pagination
                    v-model="list.current_page"
                    :total-items="list.total"
                    :items-per-page="list.per_page"
                    @change="changePage"
                    v-if="list.last_page>1"
            />
        </div>
        <van-popup v-model="showPopup" style="width: 90%;height: 90vh; overflow-y: scroll;" closeable>
            <div v-if="cards.length==0" style="text-align: center; line-height: 90vh;"><van-loading>加载中...</van-loading></div>
            <div style="padding:10px;">
                <div style="padding: 10px;text-align: center; font-weight: bold;">卡密清单</div>
                <van-row v-for="item in cards" style="font-size:12px;padding:5px 0px;">
                    <van-col span="18">{{item.card_no}}</van-col>
                    <van-col span="6" style="text-align: right;">
                        <span style="color: red;" v-if="item.actived">已使用</span>
                        <span style="color: #008800;" v-else="item.actived">未使用</span>
                    </van-col>
                </van-row>
            </div>
        </van-popup>
    </div>
</template>

<script>
    import global_ from '../Global';
    import { Toast } from 'vant';
    export default {
        name: "cardlist",
        data(){
          return {
              list:[],
              cards:[],
              showPopup:false
          }  
        },
        created(){
          this.loadInfo(1);
        },
        methods:{
            onClickLeft:function () {
                this.$router.go(-1);
            },
            changeTab:function () {
                this.loadInfo(1);
            },
            changePage:function(page){
                this.loadInfo(page);
            },
            loadInfo:function (page) {
                var toast = Toast.loading({
                    mask: true,
                    duration: 0,
                    message: '加载中...'
                });
                this.$axios.get(global_.serverUrl+"admin/card/orderlist",{
                    params:{
                        page:page
                    }
                }).then((res)=>{
                    toast.clear();
                    if(res.code == 1){
                        this.list = res.data;
                    }
                }).catch(()=>{
                    toast.clear();
                });
            },
            showCards:function (orderid) {
                this.cards = [];
                this.showPopup = true;
                this.$axios.get(global_.serverUrl+"admin/card/getcards",{
                    params:{
                        orderid:orderid
                    }
                }).then((res)=>{
                    if(res.code == 1){
                        this.cards = res.data;
                    }
                });
            }
        }
    }
</script>

<style scoped>
    .item-box{
        background: #ffffff;
        padding:5px 10px;
        margin: 10px 0px;
    }
    .item-box .item-title{
        border-bottom: #dcdee1 1px solid;
        padding: 10px;
        font-size: 14px;
    }
    .item-box .item-title .order{
        font-weight: bold;
    }
    .item-box .item-title .money{
        text-align: right;
        font-size: 16px;
    }
    .item-box .item-title .money .red{
        font-weight: bold;
        color: #fa5c6d;
    }
    .item-box .item-title .money .blue{
        font-weight: bold;
        color: blue;
    }
    .item-box .item-title .money .grey{
        font-weight: bold;
        color: #7d7e80;
    }
    .item-row{
        color: #7d7e80;
        padding: 5px 10px;
        font-size: 12px;
    }
    .item-box .text{
        background: #f8f8f8;
        border-radius: 10px;
        padding: 20px;
    }
</style>
